package com.tomriff.moneymaker.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.TextBox;

public class CreateProduct extends Composite {

	final MoneymakerMessages messages = GWT.create(MoneymakerMessages.class);;
	FlowPanel createProductPanel = new FlowPanel();
	Button createProductButton = new Button(messages.createProduct());
	TextBox productName = new TextBox();

	public CreateProduct(String productNamePar,
			final DialogBox createProductDialog) {
		createProductPanel.setPixelSize(400, 300);
		productName.setTitle(messages.productName());
		productName.setText(productNamePar);
		productName.setFocus(true);
		createProductPanel.add(productName);
		createProductPanel.add(createProductButton);

		addCloseButton(createProductDialog);

		initWidget(createProductPanel);
	}

	private void addCloseButton(final DialogBox createProductDialog) {
		Button closeDialogButton = new Button(messages.close());
		createProductPanel.add(closeDialogButton);

		closeDialogButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				createProductDialog.hide();
			}
		});
	}

}
